<template>
	<view>
		<view class="u-padding-20 info_list">
			<view class="info_list_title">工作日志</view>
			<view class="info_box" v-for="(item,index) in logs">
				<view class="info_box_title">
					
						<view class="info_box_title_time">
							上报时间：{{$u.timeFormat(item.inDate, 'yyyy年mm月dd日')}}
						</view>
					
						<view class="info_box_title_status" style="margin-top: -10rpx;">
							<u-button size="mini" @click="toEdit(item)" style="">选取</u-button>
						</view>
					
				</view>
				<view class="info_box_content">
					<view class="info_box_content_item"><text class="line_lable">主题：</text>{{item.activityTitle}}</view>
					<view class="info_box_content_item"><text class="line_lable">时间：</text>{{$u.timeFormat(item.activityDate, 'yyyy年mm月dd日')}}</view>
					<view class="info_box_content_item"><text class="line_lable">地点：</text>{{item.cityName+item.countyName+item.villageName+item.place}}</view>
					<view class="info_box_content_item"><text class="line_lable">内容：</text><rich-text :nodes="image_format(item.activityContent)"></rich-text></view>
				</view>
			</view>
		

		</view>
	</view>
</template>

<script>
	import request from '../../util/request.js'
	import api from '../../util/api.js'
	import check from '../../util/check.js'
	export default {
		data() {
			return {
				page:1,
				pageSize:10,
				userInfo:'',
				logs:'',
				itemId:'',
				isLoadMore:true
			}
		},
		onPullDownRefresh() {
			console.log('refresh');
		
			this.getLogs()
		},
		onReachBottom(){  //上拉触底函数
			  if(this.isLoadMore){  //此处判断，上锁，防止重复请求
					console.log("触发");
					this.isLoadMore=true
					this.page+=1
					this.getLogs()
			  }else{
				  uni.showToast({
					icon:'none',
				  	title:"没有更多记录了"
				  })
			  }
		},
		onLoad(options) {
			this.userInfo=check.checkLogin();
			this.itemId=options.itemId;
			this.getLogs();
		},
		methods: {
			getLogs:function(){
				uni.showLoading({
					title:'数据加载中...'
				})
				request.post(api.logList,{
					asc:'true',
					page:this.page,
					pageSize:this.pageSize,
					// userId:this.userInfo.uid
				// // 	todo 修改测试数据
					userId:'a75a707227894afcbf78c88acd90ce3d'
				 }).then(response=>{
					console.log(response);
					uni.hideLoading();
					if(this.page==1){
						this.logs=response.data.data.records;
					}else{
						
						
						var list=this.logs.concat(response.data.data.records);
						this.logs=list;	
					}
					if(this.logs.length>=response.data.data.total){
						this.isLoadMore=false;
					}
					uni.hideLoading();
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试',
						
					})
				})
			},
			image_format:function(value){
				value=value.replace("height=","h=");
				 var regex = new RegExp('<img', 'gi');
				 value= value.replace(regex, `<img style="max-width: 100% !important;; height:300rpx !important;"`);
				 return value;
				
			},
			toEdit: function(item) {
				uni.showLoading({
					title:'处理中...'
				})
				uni.setStorageSync('log',item);
				uni.redirectTo({
					url: '../form/copy?itemId='+this.itemId
				})
			}
		}
	}
</script>

<style>
	.info_box {
		background-color: #FFFFFF;
		padding: 10rpx;
		border: solid 1px #f4f4f5;
		margin-bottom: 20rpx;
		border-radius: 5rpx;
	}
	.line_lable{
		font-weight: bold;
	}

	.info_box_title {
		border-bottom: solid 1px #f4f4f5;
		height: 65rpx;
		line-height: 65rpx;
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
		align-items: center;
		padding: 0 10px;
		justify-content:space-between
	}

	.info_box_title_time {
		flex:1
	}
	.info_list_title {
		border-left: solid 10rpx #0095f0;
		padding: 0 5rpx;
		margin: 20rpx 0;
		font-size: 35rpx;
		font-weight: 500;
	}

	.info_list {}

	.info_box_content {
		padding: 20rpx;
	}

	.info_box_content_item {
		padding: 10rpx 0;
	}

	.info_box_content_image {
		width: 300rpx;
		height: 200rpx;
		margin-right: 10rpx;
	}
</style>
